package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.RecordOrganoleptic;
import com.water_work_form.entity.RecordPotentialPh;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.RecordPotentialPhService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * <p>
 * 记录——电位法检测pH原始记录 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-09-14
 */
@RestController
@RequestMapping("/record-potential-ph")
public class RecordPotentialPhController {

    @Autowired
    RecordPotentialPhService recordPotentialPhService;

    /**
     * 记录——电位法检测pH原始记录 项目新增
     * @param recordPotentialPh 新数据
     * @return 返回对应code 0为成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addRecordPotentialPh(@RequestBody RecordPotentialPh recordPotentialPh){
        recordPotentialPh.setId(RandomIdUtil.createRandomId());
        recordPotentialPhService.save(recordPotentialPh);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, recordPotentialPh);
    }

    /**
     * 记录——电位法检测pH原始记录 项目查询（两个查询项+分页）
     * @param checkStartDate 检测日期（check_date）范围查询的开始日期
     * @param checkEndDate 检测日期（check_date）范围查询的结束日期
     * @param checkSite 检测地点（check_site）
     * @param current 分页查询 当前页数
     * @param size 分页查询 每页最大数据量
     * @return 返回上述查询后的数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listRecordPotentialPh(@RequestParam("checkStartDate") String checkStartDate, @RequestParam("checkEndDate") String checkEndDate, @RequestParam("checkSite") String checkSite,
                                        @RequestParam("status") String status, @RequestParam("current") Integer current, @RequestParam("size") Integer size){
        IPage<RecordPotentialPh> page = recordPotentialPhService.selectRecordPotentialPh(checkStartDate, checkEndDate, checkSite, status, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 记录——电位法检测pH原始记录 项目查询
     * @param id 需要删除的项目id
     * @return 返回对应result，code 0为成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteRecordPotentialPh(@RequestParam("id") Long id){
        recordPotentialPhService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——电位法检测pH原始记录 项目更新
     * @param recordPotentialPh 需要更新的项目
     * @return 返回对应result，code 0为成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateRecordPotentialPh(@RequestBody RecordPotentialPh recordPotentialPh){
        recordPotentialPhService.updateById(recordPotentialPh);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——电位法检测pH原始记录 基础表数据查询
     * @param name form表name
     * @param type device表type
     * @param restrictionName restriction表name
     * @param waterId water表id
     * @param batchNumber1 ph_liquid表batch_number
     * @param batchNumber2 ph_liquid表batch_number
     * @param batchNumber3 ph_liquid表batch_number
     * @param diluteNo ph_dilute表dilute_no
     * @return 返回符合上述条件的数据
     */
    @ApiOperation("基础表数据查询")
    @GetMapping("/basicList")
    public Result listBasicPotentialPh( @RequestParam("name") String name, @RequestParam("type") String type, @RequestParam("restrictionName") String restrictionName,
                                        @RequestParam("waterId") String waterId, @RequestParam("batchNumber1") String batchNumber1, @RequestParam("batchNumber2") String batchNumber2,
                                        @RequestParam("batchNumber3") String batchNumber3, @RequestParam("diluteNo") String diluteNo){
        Map<String,Object> map = recordPotentialPhService.selectBasicPotentialPh(name, type, restrictionName, waterId, batchNumber1, batchNumber2, batchNumber3, diluteNo);
        return ResultUtil.success(ResultCodeEnum.SUCCESS,map);
    }

    /**
     * 记录——电位法检测pH原始记录 数据表导出
     * @param recordPotentialPh 需要导出的数据列表
     * @return 返回相应数据
     * @throws IOException 异常
     */
    @ApiOperation("列表导出")
    @PostMapping(value = "/download-word")
    public Result downloadWordRecordPotentialPh(@RequestBody RecordPotentialPh recordPotentialPh) throws IOException  {
        recordPotentialPhService.downloadRecordPotentialPh(recordPotentialPh);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

}

